package com.solarStruggle.controls

import java.awt.{Font, Color}
import javax.swing.{ImageIcon}
import javax.swing.border.{EmptyBorder, LineBorder}
import scala.swing.{Alignment, Component, Label, ListView}
import graphics.Svg
import util.ResourceLoader

class SvgIconListRenderer[Type](textFn: Type => String, svgFilenameFn: Type => String)
extends ListView.Renderer[Type] {

	override def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: Type, index: Int): Component = {
		val highlight = isSelected || hasFocus
		new Label {
/*			font = Fonts.sansation.deriveFont(Font.PLAIN, 14f) 
			foreground = new Color(24, 24, 24)
			opaque = true
			background = if(highlight) new Color(192, 192, 255) else new Color(255, 255, 255)
			border = if(highlight) new LineBorder(new Color(192, 192, 192)) else new EmptyBorder(5, 5, 5, 5) */
			horizontalTextPosition = Alignment.Left
			verticalTextPosition = Alignment.Center
			icon = new ImageIcon(new Svg(24, 24, ResourceLoader.getResource("svg/" + svgFilenameFn(a)), "#000099").createImage())
			text = textFn(a)
		}
	}
}
